package com.winning.juc;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Hao.Y
 */
public class TestAtomicDemo {

    public static void main(String[] args) {
        AtomicDemo atomicDemo = new AtomicDemo();
        for (int i = 0; i < 10; i++) {
            new Thread(atomicDemo).start();
        }

    }

}

class AtomicDemo implements Runnable{

    private AtomicInteger serialNumber = new AtomicInteger(1);

    @Override
    public void run() {

        try {
            Thread.sleep(200);
            System.out.println(getSerialNumber());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    public int getSerialNumber() {
        return serialNumber.getAndIncrement();
    }

}
